package com.woniuxy.oa.dao.provider;

import com.woniuxy.oa.entity.Dept;
import org.apache.ibatis.jdbc.SQL;

/**
 * @Auther: M
 * @Date: 2019/12/25 17:25
 * @Description: 部门查询条件
 */
public class DeptProvider {
    public String getAllDeptByCondition(Dept dept){
        return new SQL(){
            {
                SELECT("d.*,e.name empName,e.id empId,e.phonenum,e.email").FROM("oa_dept d").LEFT_OUTER_JOIN("oa_emp e on e.id=d.empid");
                if(dept==null){
                    WHERE("");
                }
                if(dept.getDeptName()!=null && dept.getDeptName().trim().length()!=0 ){
                    WHERE("deptname like concat(\"%\",#{deptName},\"%\")");
                }
                if(dept.getEmp()!=null){
                    if(dept.getEmp().getId()!=null && dept.getEmp().getId().trim().length()!=0){
                        WHERE("empid=#{empId}");
                    }
                }

            }
        }.toString();
    }
}